<?php

namespace App\Models\Payment\Platform;

abstract class BasePlatform
{
    const TIMEOUT = 5;
    const GATEWAY = '';
    const GATEWAY_DEV = '';

    protected $uri;
    protected $gateway;
    protected $method = 'post';
    protected $body;
    protected $logger;
    protected $name;
    protected $timestamp;
    protected $nonceStr;

    const NOTIFY_URI = '/api/payment/notify/paid/';

    abstract protected static function nonceStr(): string;

    abstract protected static function timestamp(): string;

    abstract protected function signature(): string;

    abstract protected function fire();

    abstract protected function notifySignCheck($rawNotifyDat): bool;

    protected function notifyUrl(string $payType, string $paymentChannelID): string
    {
        if (!$host = config('app.url')) {
            throw new \Exception('域名未配置');
        }

        $payType = strtolower($payType);

        return $host . self::NOTIFY_URI . "{$payType}/{$paymentChannelID}";
    }
}
